package cn.quevo.cube.api.data;

import cn.quevo.common.annotation.RequiresPermissions;
import cn.quevo.common.entity.ResultEntity;
import cn.quevo.common.enums.ResultStatusEnum;
import cn.quevo.common.lang.StringUtils;
import cn.quevo.core.spring.SpringController;
import cn.quevo.cube.provide.data.entity.CubeModelDataDetail;
import cn.quevo.cube.provide.data.entity.query.CubeModelDataDetailQuery;
import cn.quevo.cube.provide.data.service.CubeModelDataDetailService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 数据记录明细 RestController
 *
 * @author July july_sky@foxmail.com
 * @version 1.0
 * @date 2018/12/11 14:58:02
 * @Copyright 湘豫（北京）科技有限公司版权所有.All Rights Reserved.
 */
@RestController("cubeModelDataDetailController")
@RequestMapping("/cube/")
public class CubeModelDataDetailRestController extends SpringController{

    @Resource(name="cubeModelDataDetailService")
    private CubeModelDataDetailService cubeModelDataDetailService;

    /**
     * 分页加载数据记录明细
     *
     * @param cubeModelDataDetailQuery
     * @return
     * @author July july_sky@foxmail.com
     * @date 2018/12/11 14:58:02
     */
    @RequestMapping(value="cubeModelDataDetail",method= RequestMethod.GET)
    @RequiresPermissions("cube:cubeModelDataDetail:list")
    public ResultEntity page(CubeModelDataDetailQuery cubeModelDataDetailQuery){
        return cubeModelDataDetailService.getPage(cubeModelDataDetailQuery);
    }

    /**
     * 保存数据记录明细
     *
     * @param cubeModelDataDetail
     * @return
     * @author July july_sky@foxmail.com
     * @date 2018/12/11 14:58:02
     */
    @RequestMapping(value="cubeModelDataDetail",method=RequestMethod.POST)
    @RequiresPermissions("cube:cubeModelDataDetail:create")
    public ResultEntity create(CubeModelDataDetail cubeModelDataDetail){
        if(cubeModelDataDetailService.create(cubeModelDataDetail) <= 0){
            return new ResultEntity(ResultStatusEnum.RECORD_REPEAT);
        }
        return ResultEntity.success();
    }

    /**
     * 修改数据记录明细
     *
     * @param cubeModelDataDetail
     * @param id
     * @return
     * @author July july_sky@foxmail.com
     * @date 2018/12/11 14:58:02
     */
    @RequestMapping(value="cubeModelDataDetail//{id:\\d+}",method=RequestMethod.PUT)
    @RequiresPermissions("cube:cubeModelDataDetail:update")
    public ResultEntity update(CubeModelDataDetail cubeModelDataDetail, @PathVariable("id") Long id){
        if (StringUtils.isBlank(id)) {
            return ResultEntity.fail(ResultStatusEnum.RECORD_UNSELECTED);
        }
        cubeModelDataDetail.setId(id);
        if (StringUtils.isBlank(this.cubeModelDataDetailService.update(cubeModelDataDetail))) {
            return ResultEntity.fail(ResultStatusEnum.RECORD_REPEAT);
        }
        return ResultEntity.success();
    }
}
